package com.kun.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kun.entity.Charity;
import com.kun.entity.CharityExample;
import com.kun.entity.CharityExample.Criteria;
import com.kun.mapper.cluster.ClusterCharityMapper;
import com.kun.mapper.master.MasterCharityMapper;
import com.kun.service.CharityService;

/**
 * @description: 
 * @author: KM
 * 2018年4月26日 下午11:11:08
 */
@Service
public class CharityServiceImpl implements CharityService {
	
	@Autowired
	private MasterCharityMapper masterCharityMapper;
	
	@Autowired
	private ClusterCharityMapper clusterCharityMapper;
	
	public int insertCharity(Charity charity){
		return masterCharityMapper.insertSelective(charity);
	}
	
	/**
	 * @Description: 根据条件更新
	 * @param: Charity，CharityExample
	 */
	public int updateCharity(Charity charity,CharityExample ce){
		return masterCharityMapper.updateByExampleSelective(charity, ce);
	}
	
	
	
	/**
	 * @Description: 根据用户图书编号查询
	 * @param: userId，booknumber，state
	 */
	public List<Charity> selectCharityByUserIdAndBooknumber(String userId,String booknumber,String state){
		CharityExample ce = new CharityExample();
		Criteria c = ce.createCriteria();
		ce.setOrderByClause("add_time desc");
		c.andUserIdEqualTo(userId);
		c.andBookNumberEqualTo(booknumber);
		c.andStateEqualTo(state);
		List<Charity> lc = clusterCharityMapper.selectByExample(ce);
		return lc;
		
	}

	@Override
	public int updateCharityByKey(Charity charity) {
		return masterCharityMapper.updateByPrimaryKeySelective(charity);
	}

}
